<template>
  <div class="agreement">
    <div class="common">
      <div class="common-button" @click="editHit(0)">新增</div>
    </div>

    <div class="table" v-loading="loading">
      <el-table
        :data="tableData"
        border
        :header-cell-style="{
          color: '#333333',
          backgroundColor: '#f3f3f3',
        }"
      >
        <el-table-column prop="agreementName" label="协议名称">
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="200">
          <template slot-scope="scope">
            <div class="operation">
              <div class="list" @click.prevent="editHit(1, scope.row)">
                编辑
              </div>
            </div>
          </template>
        </el-table-column>
      </el-table>

      <div class="pagination">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          background
          layout="prev, pager, next"
          :total="tableDataTotal"
          :current-page="page"
        >
        </el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { systemAgreementList } from "@/api/system";

export default {
  data() {
    return {
      //-------------
      page: 1,
      limit: 10,
      tableData: [],
      tableDataTotal: 0,
      addRoaid: 0,
      agreementObj: {},
      loading: false,
    };
  },
  created() {
    this.loading = true;
    this.systemAgreementListMet();
  },
  methods: {
    systemAgreementListMet() {
      let params = {
        pageSize: this.limit,
        pageNo: this.page,
      };

      systemAgreementList(params).then((res) => {
        if (res.errorCode == null) {
          this.tableData = res.resultData;
          this.tableDataTotal = res.resultData.length;

          this.loading = false;
        }
      });
    },
    //-------------
    editHit(index, item) {
      if (index == 1) {
        this.$router.push({
          path: "/system/agreement-edit",
          query: {
            id: item.agreementId,
            soucre: 0,
          },
        });
      } else {
        this.$router.push({
          path: "/system/agreement-edit",
          query: {
            soucre: 0,
          },
        });
      }
    },
    //---------
    handleSizeChange(val) {
      this.limit = val;
      this.loading = true;
      this.systemAgreementListMet();
    },
    handleCurrentChange(val) {
      this.page = val;
      this.loading = true;
      this.systemAgreementListMet();
    },
  },
};
</script>

<style lang="less" scoped>
.agreement {
  .common {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    .common-button {
      padding: 9px 20px;
      box-sizing: border-box;
      border-radius: 5px;
      background: #2a82e4;
      font-size: 14px;
      color: #fff;
      cursor: pointer;
      margin-left: 0;
    }
  }

  .table {
    cursor: pointer;

    .operation {
      display: flex;
      align-items: center;
      color: #2a82e4;
    }
  }
}
</style>